package com.ruoyi.project.gxgw_modules.clue.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.gxgw_modules.clue.domain.Clue;
import com.ruoyi.project.gxgw_modules.clue.service.IClueService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 线索记录 信息操作处理
 * 
 * @author ruoyi
 * @date 2019-01-21
 */
@Controller
@RequestMapping("/gxgw_modules/clue")
public class ClueController extends BaseController
{
    private String prefix = "gxgw_modules/clue";
	
	@Autowired
	private IClueService clueService;
	
	@RequiresPermissions("gxgw_modules:clue:view")
	@GetMapping()
	public String clue()
	{
		System.out.println(prefix + "/clue");
	    return prefix + "/clue";
	}
	
	/**
	 * 查询线索记录列表
	 */
	@RequiresPermissions("gxgw_modules:clue:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Clue clue)
	{
		startPage();
        List<Clue> list = clueService.selectClueList(clue);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出线索记录列表
	 */
	@RequiresPermissions("gxgw_modules:clue:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Clue clue)
    {
    	List<Clue> list = clueService.selectClueList(clue);
        ExcelUtil<Clue> util = new ExcelUtil<Clue>(Clue.class);
        return util.exportExcel(list, "clue");
    }
	
	/**
	 * 新增线索记录
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存线索记录
	 */
	@RequiresPermissions("gxgw_modules:clue:add")
	@Log(title = "线索记录", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(Clue clue)
	{		
		return toAjax(clueService.insertClue(clue));
	}

	/**
	 * 修改线索记录
	 */
	@GetMapping("/edit/{clueId}")
	public String edit(@PathVariable("clueId") Integer clueId, ModelMap mmap)
	{
		Clue clue = clueService.selectClueById(clueId);
		mmap.put("clue", clue);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存线索记录
	 */
	@RequiresPermissions("gxgw_modules:clue:edit")
	@Log(title = "线索记录", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(Clue clue)
	{		
		return toAjax(clueService.updateClue(clue));
	}
	
	/**
	 * 删除线索记录
	 */
	@RequiresPermissions("gxgw_modules:clue:remove")
	@Log(title = "线索记录", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(clueService.deleteClueByIds(ids));
	}
	
}
